home *** CD-ROM | disk | FTP | other *** search
/ boe.pres.k12.wv.us / boe.pres.k12.wv.us.zip / boe.pres.k12.wv.us / Utilities / Xerox Workcentre 5335 / Windows Scan / 32-bit_x86 / Francais / cpsimage.cab / data / xipProcs / printLayer.proc < prev    next >
Text File  |  2009-03-16  |  16KB  |  484 lines

  1.  
  2.  
  3. /* Dynamically load necessary functions */
  4. LoadClasses (filename: "xeng");
  5.  
  6. /* @PrintLayerAttributes
  7.   // DESCRIPTION
  8.   Print the XIPIMAGE image attributes for the given image layer.
  9.   Take in an XIPIMAGE and optional layer number and returns a STRING with
  10.   the detailing the image attributes, i.e., pixels = xx, scanlines = xx, etc.
  11. */
  12.  
  13. PROCEDURE PrintLayerAttributes (XIPIMAGE img, INTEGER layerNum)
  14.   RETURNS (STRING s)
  15. {
  16.   s = "Image Info for layer" + layerNum + "\n" +
  17.    "   pixels       " + img.getMember(num:layerNum, member:"pixels") + "\n" +
  18.    "   scanlines    " + img.getMember(num:layerNum, member:"scanlines") + "\n" +
  19.    "   seps         " + img.getMember(num:layerNum, member:"seps") + "\n" +
  20.    "   bits         " + img.getMember(num:layerNum, member:"bits") + "\n" +
  21.    "   bytes        " + img.getMember(num:layerNum, member:"bytes") + "\n" +
  22.    "   compression  " + CompType(comp:img.getMember(num:layerNum, member:"compression"))+"\n"+
  23.    "   width,height " + img.getMember(num:layerNum, member:"width") + ","
  24.                       + img.getMember(num:layerNum, member:"height") + "\n" +
  25.    "   xres,yres    " + img.getMember(num:layerNum, member:"xres") + ","
  26.                       + img.getMember(num:layerNum, member:"yres") + "\n" +
  27.    "   interleave   " + img.getMember(num:layerNum, member:"interleave") + "\n" +
  28.    "   layerType    " + LayerType(layer:img.getMember(num:layerNum, member:"layerType"))+"\n";
  29.  
  30.    if ( img.getAttr (num: layerNum, name: "subLayerType") )
  31.       s = s + "      subLayerType = " +
  32.           img.getAttr (num: layerNum, name: "subLayerType") + "\n";
  33.  
  34.   s = s +
  35.    "   xpos,ypos    " + img.getMember(num:layerNum, member:"xpos") + "," +
  36.                         img.getMember(num:layerNum, member:"ypos") + "\n" +
  37.    "   photometry   " + Photo2Str (photo: img.getMember(num:layerNum, member:"photometry"))+
  38.                     "\n";
  39.  
  40.   s = s + "   mediaColor: \n";
  41.   XIPCOLOR xipcolor = img.getMember(num:layerNum, member:"mediaColor");
  42.   if ( xipcolor ) {
  43.      s = s + "      photometry: " + Photo2Str (photo: xipcolor.photometry)+"\n";
  44.      if (xipcolor.getSeps () == 1)
  45.         s = s + "      color vals: " + xipcolor.c[0] + "\n";
  46.      else
  47.         s = s + "      color vals: " + xipcolor.c[0]+","+xipcolor.c[1]+","+
  48.                                      + xipcolor.c[2]+","+xipcolor.c[3]+"\n";
  49.      }
  50.   else s = s + "\tmediaColor is NULL\n";
  51.   
  52.   s = s + "   color: \n";
  53.   xipcolor = img.getMember(num:layerNum, member:"color");
  54.   if ( xipcolor ) {
  55.      DOUBLE adjust = 1.0;
  56.      s = s + "      photometry: " + Photo2Str (photo: xipcolor.photometry)+"\n";
  57.      if (xipcolor.getSeps () == 1)
  58.         s = s + "      color vals: " + (xipcolor.c[0]/adjust) + "\n";
  59.      else
  60.         s = s + "      color vals: " + (xipcolor.c[0]/adjust) + ","
  61.                                      + (xipcolor.c[1]/adjust) + ","
  62.                                      + (xipcolor.c[2]/adjust) + ","
  63.                                      +  xipcolor.c[3] + "\n";
  64.      }
  65.   else s = s + "\tcolor is NULL\n";
  66. }
  67.  
  68.  
  69. /* @IsRasterLayer
  70.   // DESCRIPTION
  71.   Given a layer type value, returns TRUE if the value specifies a raster
  72.   layer type; and returns FALSE otherwise.
  73. */
  74. PROCEDURE IsRasterLayer (INTEGER layerType)
  75.   RETURNS (BOOLEAN result)
  76. {
  77.    result = FALSE;
  78.    if ((layerType == XIP_Binary)    || (layerType == XIP_Contone)     ||
  79.        (layerType == XIP_ColorMask) || (layerType == XIP_ContoneMask) ||
  80.        (layerType == XIP_Thumbnail))
  81.       result = TRUE;
  82. }
  83.  
  84. /* @LayerType
  85.   // DESCRIPTION
  86.   Map integer for layerType to a name.  Returns a STRING value.
  87. */
  88. PROCEDURE LayerType (INTEGER layer)
  89.   RETURNS (STRING name)
  90. {
  91.   name = "XIP_Contone";
  92.  
  93.   if (layer == XIP_ContoneMask)         name = "XIP_ContoneMask";
  94.   else if (layer == XIP_ColorMask)      name = "XIP_ColorMask";
  95.   else if (layer == XIP_ColorRectangle) name = "XIP_ColorRectangle";
  96.   else if (layer == XIP_JBIG2Dict)      name = "XIP_JBIG2Dict";
  97.   else if (layer == XIP_Thumbnail)      name = "XIP_Thumbnail";
  98.   else if (layer == XIP_Binary)         name = "XIP_Binary";
  99.   else if (layer == XIP_Tag)            name = "XIP_Tag";
  100.   else if (layer == XIP_Text)           name = "XIP_Text";
  101. }
  102.  
  103.  
  104. /* @CompType
  105.   // DESCRIPTION
  106.   Map integer for compression to a name.  Returns a STRING value.
  107. */
  108. PROCEDURE CompType (INTEGER comp)
  109.   RETURNS (STRING name)
  110. {
  111.   name = "uncompressed";
  112.  
  113.   if (comp == XIP_JPEG_COMP)            name = "jpeg";
  114.   else if (comp == XIP_CCITT_G3_COMP)   name = "ccitt g3";
  115.   else if (comp == XIP_CCITT_G4_COMP)   name = "ccitt g4";
  116.   else if (comp == XIP_CCITT_G32D_COMP) name = "ccitt g32d";
  117.   else if (comp == XIP_FG_COMP)         name = "fg";
  118.   else if (comp == XIP_DEFLATE_COMP)    name = "deflate";
  119.   else if (comp == XIP_JBIG2_COMP)      name = "jbig2";
  120.   else if (comp == XIP_JPEG2000_COMP)   name = "jpeg2000";
  121.   else if (comp == XIP_LZW_COMP)        name = "lzw";
  122.   else if (comp == XIP_XLZ)             name = "xlz";
  123.   else if (comp == XIP_JPEGthenDEFLATE) name = "jpeg+deflate";
  124. }
  125.  
  126.  
  127. /* @Photo2Str
  128.   // DESCRIPTION
  129.   Given a photometery number, map it to the corresponding string name.
  130.   For example, CMYK internally is represented by the number 6.  Calling
  131.   this procedure with the number 6 returns the string "CMYK".  Returns
  132.   a STRING value.
  133. */ 
  134.  
  135. PROCEDURE Photo2Str (INTEGER photo)
  136.   RETURNS (STRING name)
  137. {
  138.    if (photo == XIP_ACRGB_COLOR)            name = "acrgb";
  139.    else if (photo == XIP_BGR_COLOR)         name = "bgr";
  140.    else if (photo == XIP_CIECAM97S_COLOR)   name = "ciecam97S";
  141.    else if (photo == XIP_CIELAB_COLOR)      name = "cielab";
  142.    else if (photo == XIP_CIELCH_COLOR)      name = "cielch";
  143.    else if (photo == XIP_CIELUV_COLOR)      name = "cielub";
  144.    else if (photo == XIP_CMY_COLOR)         name = "cmy";
  145.    else if (photo == XIP_CMYK_COLOR)        name = "cmyk";
  146.    else if (photo == XIP_DEVICECMY_COLOR)   name = "DeviceCMY";
  147.    else if (photo == XIP_DEVICECMYK_COLOR)  name = "DeviceCMYK";
  148.    else if (photo == XIP_DEVICERGB_COLOR)   name = "DeviceRGB";
  149.    else if (photo == XIP_FAXLAB_COLOR)      name = "faxlab";
  150.    else if (photo == XIP_GENGRAY_COLOR)     name = "gengray";
  151.    else if (photo == XIP_GENRGB_COLOR)      name = "genrgb";
  152.    else if (photo == XIP_GRAY_COLOR)        name = "gray";
  153.    else if (photo == XIP_SGRAY_COLOR)       name = "slum";
  154.    else if (photo == XIP_HCLAB_COLOR)       name = "hclab";
  155.    else if (photo == XIP_HSV_COLOR)         name = "hsv";
  156.    else if (photo == XIP_ICCXYZ_COLOR)      name = "iccxyz";
  157.    else if (photo == XIP_ITUL_COLOR)        name = "itul";
  158.    else if (photo == XIP_ITULAB_COLOR)      name = "itulab";
  159.    else if (photo == XIP_K_COLOR)           name = "klinear";
  160.    else if (photo == XIP_KODAKYCBCR_COLOR)  name = "Kodakycbcr";
  161.    else if (photo == XIP_LMS_COLOR)         name = "lms";
  162.    else if (photo == XIP_RLAB_COLOR)        name = "rlab";
  163.    else if (photo == XIP_ROMMRGB_COLOR)     name = "rommrgb";
  164.    else if (photo == XIP_SBGR_COLOR)        name = "sbgr";
  165.    else if (photo == XIP_SRGB_COLOR)        name = "srgb";
  166.    else if (photo == XIP_XRGB_COLOR)        name = "xrgb";
  167.    else if (photo == XIP_XYY_COLOR)         name = "xyy";
  168.    else if (photo == XIP_XYZ_COLOR)         name = "xyz";
  169.    else if (photo == XIP_YCBCR_COLOR)       name = "ycbcr";
  170.    else if (photo == XIP_YCC_COLOR)         name = "ycc";
  171.    else if (photo == XIP_YES_COLOR)         name = "yes";
  172.    else if (photo == XIP_YHS_COLOR)         name = "yhs";
  173.    else name = "unknown";
  174. }
  175.  
  176. /* @PhotoIsRGB
  177.   // DESCRIPTION
  178.   Given a photometery number, returns 1 if the photometry specifies an
  179.   RGB color space; and 0 otherwise.
  180. */
  181.  
  182. private
  183. PROCEDURE PhotoIsRGB (INTEGER photo)
  184.   RETURNS (INTEGER result)
  185. {
  186.   if ((photo == XIP_XRGB_COLOR) ||
  187.       (photo == XIP_ACRGB_COLOR) ||
  188.       (photo == XIP_ROMMRGB_COLOR) ||
  189.       (photo == XIP_SRGB_COLOR) ||
  190.       (photo == XIP_GENRGB_COLOR) ||
  191.       (photo == XIP_DEVICERGB_COLOR) ||
  192.       (photo == XIP_BGR_COLOR) ||
  193.       (photo == XIP_SBGR_COLOR))
  194.     result = 1;
  195.   else
  196.     result = 0;
  197. }
  198.  
  199. /* @PhotoIsGray
  200.   // DESCRIPTION
  201.   Given a photometery number, returns 1 if the photometry specifies an
  202.   gray color space; and 0 otherwise.
  203. */
  204.  
  205. private
  206. PROCEDURE PhotoIsGray (INTEGER photo)
  207.   RETURNS (INTEGER result)
  208. {
  209.   if ((photo == XIP_GRAY_COLOR) ||
  210.       (photo == XIP_GENGRAY_COLOR) ||
  211.       (photo == XIP_SGRAY_COLOR) ||
  212.       (photo == XIP_K_COLOR) ||
  213.       (photo == XIP_ITUL_COLOR) ||
  214.       (photo == XIP_DEVICEGRAY_COLOR))
  215.     result = 1;
  216.   else
  217.     result = 0;
  218. }
  219.  
  220. /* @GetImageSeps
  221.   // DESCRIPTION
  222.   Given a photometery number, returns the number of separations for that
  223.   photometry.
  224. */
  225.  
  226. private
  227. PROCEDURE GetImageSeps (INTEGER photo)
  228.   RETURNS (INTEGER seps)
  229. {
  230.   if ((photo == XIP_GRAY_COLOR) ||
  231.       (photo == XIP_DEVICEGRAY_COLOR) ||
  232.       (photo == XIP_SGRAY_COLOR) ||
  233.       (photo == XIP_K_COLOR) ||
  234.       (photo == XIP_GENGRAY_COLOR) ||
  235.       (photo == XIP_ITUL_COLOR) ||
  236.       (photo == XIP_BUILDMAP_COLOR))
  237.     seps = 1;
  238.   else if ((photo == XIP_CMYK_COLOR) ||
  239.            (photo == XIP_DEVICECMYK_COLOR))
  240.     seps = 4;
  241.   else if (photo == XIP_MULTIPART_COLOR)
  242.     seps = -1;
  243.   else
  244.     seps = 3;
  245. }
  246.  
  247. /* @XIPColorChangespace
  248.   // DESCRIPTION
  249.   Given a color and a photometry value, converts the input color to the
  250.   specified color space.
  251. */
  252.  
  253. private
  254. PROCEDURE XIPColorChangespace (XIPCOLOR incolor, INTEGER photo)
  255.   RETURNS (XIPCOLOR outcolor)
  256. {
  257.   STRING  fn = "XIPColorChangespace";
  258.   STRING  str;
  259.   STRING  tmp;
  260.   LIST    c;
  261.   INTEGER k;
  262.   INTEGER val;
  263.   INTEGER nseps;
  264.   INTEGER skipOne = FALSE;
  265.  
  266.   nseps = GetImageSeps (photo: photo);
  267.  
  268.   if (incolor.photometry == photo) {
  269.    for (k=0; k<nseps; k++)
  270.      c.insert (obj: new (INTEGER, value:incolor.c[k]), entry: k);
  271.  
  272.     outcolor.c          = c;
  273.     outcolor.photometry = incolor.photometry;
  274.   } else if (incolor.photometry == XIP_UNKNOWN_COLOR) {
  275.     print fn + ": Colorspace of input color is unknown";
  276.   } else if (photo == XIP_UNKNOWN_COLOR) {
  277.     print fn + ": Output colorspace is unknown";
  278.   } else {
  279.     str = pattern (constant: incolor.c,
  280.                    space: Photo2Str (photo: incolor.photometry)
  281.             ).cspace (outspace: Photo2Str (photo: photo), precise: 1
  282.             ).simplemap (entries: 1
  283.             ).toString (
  284.             );
  285.  
  286.     for (tmp=str.getToken (); tmp; tmp=str.getToken ())
  287.       if (tmp == "color:") {
  288.         if (!skipOne) {
  289.           str.getLine ();
  290.           skipOne = TRUE;
  291.         } else {
  292.           tmp = str.getLine ();
  293.           for (k=0; k<nseps; k++) {
  294.             val = tmp.getToken ();
  295.             c.insert (obj: new (INTEGER, value:val), entry: k);
  296.           }
  297.  
  298.           outcolor.c          = c;
  299.           outcolor.photometry = photo;
  300.         }
  301.       }
  302.   }
  303. }
  304.  
  305. /* @XIPColorCompare
  306.   // DESCRIPTION
  307.   Given two colors, compares each separation of the colors by computing the
  308.   difference of the two corresponding separations until a non-zero difference is
  309.   encountered or all separations have been compared.
  310.   
  311.   Returns -1 if difference is negative (1st color is less than 2nd color)
  312.            0 if difference is zero (1st color equals 2nd color)
  313.           +1 if difference is positive (1st color is greater than 2nd color)
  314.   
  315.   Note that this procedure converts the colorspace of the second color if it is
  316.   not in the same color space as the first color.
  317. */
  318.  
  319. private
  320. PROCEDURE XIPColorCompare (XIPCOLOR lhs, XIPCOLOR rhs)
  321.   RETURNS (INTEGER result)
  322. {
  323.   XIPCOLOR l, r;
  324.   INTEGER  k, nseps, diff;
  325.  
  326.   l = lhs;
  327.   r = XIPColorChangespace (incolor: rhs, photo: lhs.photometry);
  328.  
  329.   nseps = GetImageSeps (photo: lhs.photometry);
  330.  
  331.   diff = 0;
  332.   for (k=0; (k<nseps) && (diff == 0); k++)
  333.     diff = l.c[k] - r.c[k];
  334.  
  335.   if (diff < 0)
  336.     result = -1;
  337.   else if (diff == 0)
  338.     result = 0;
  339.   else
  340.     result = 1;
  341. }
  342.  
  343. /* @XIPColorName
  344.   // DESCRIPTION
  345.   Given a color, map it to its corresponding string name. For example, the color  (0, 255, 255) in the HSV color space maps to the string "red".
  346. */
  347.  
  348. private
  349. PROCEDURE XIPColorName (XIPCOLOR color)
  350.   RETURNS (STRING colorname)
  351. {
  352.   XIPCOLOR clr;
  353.   INTEGER  idx;
  354.   INTEGER  h, s, v;
  355.   LIST     hue = (0, 21, 42, 63, 85, 106, 127, 148, 170, 191, 212, 233, 255);
  356.   LIST     sat = (0, 63, 127, 191, 255);
  357.   LIST     val = (0, 63, 127, 191, 255);
  358.  
  359.   clr = XIPColorChangespace (incolor: color, photo: XIP_HSV_COLOR);
  360.   if (clr.photometry != XIP_HSV_COLOR) {
  361.     colorname = "unknown";
  362.     return;
  363.   }
  364.  
  365.   idx = clr.c[0] * (hue.length () - 1) / 255.0;
  366.   h = hue[idx];
  367.   if (h == 255)
  368.     h = 0;
  369.  
  370.   idx = clr.c[1] * (sat.length () - 1) / 255.0;
  371.   s = sat[idx];
  372.  
  373.   idx = clr.c[2] * (val.length () - 1) / 255.0;
  374.   v = val[idx];
  375.  
  376.   if (v == 0) {
  377.     colorname = "black";
  378.   } else if (s == 0) {
  379.     if (v == 255) {
  380.       colorname = "white";
  381.     } else if (v == 191) {
  382.       colorname = "light gray";
  383.     } else if (v == 127) {
  384.       colorname = "gray";
  385.     } else { /* v == 63 */
  386.       colorname = "dark gray";
  387.     }
  388.   } else if (h == 0) {
  389.     colorname = "red";
  390.   } else if (h == 21) {
  391.     colorname = "orange";
  392.   } else if (h == 42) {
  393.     colorname = "yellow";
  394.   } else if (h == 63) {
  395.     colorname = "spring";
  396.   } else if (h == 85) {
  397.     colorname = "green";
  398.   } else if (h == 106) {
  399.     colorname = "teal";
  400.   } else if (h == 127) {
  401.     colorname = "cyan";
  402.   } else if (h == 148) {
  403.     colorname = "azure";
  404.   } else if (h == 170) {
  405.     colorname = "blue";
  406.   } else if (h == 191) {
  407.     colorname = "violet";
  408.   } else if (h == 212) {
  409.     colorname = "magenta";
  410.   } else { /* h == 233 */
  411.     colorname = "pink";
  412.   }
  413. }
  414.  
  415. /* @XIPColorClass
  416.   // DESCRIPTION
  417.   Given a color, map it to its corresponding color classification. For example,
  418.   the color (170, 255, 255) in the HSV color space maps to the color class
  419.   XIP_BLUE_CLASS, the integer 9.
  420. */
  421. private
  422. PROCEDURE XIPColorClass (XIPCOLOR color)
  423.   RETURNS (INTEGER classid)
  424. {
  425.   STRING colorname;
  426.  
  427.   /* Color class IDs */
  428.   INTEGER XIP_RED_CLASS       = 0;
  429.   INTEGER XIP_ORANGE_CLASS    = 1;
  430.   INTEGER XIP_YELLOW_CLASS    = 2;
  431.   INTEGER XIP_SPRING_CLASS    = 3;
  432.   INTEGER XIP_GREEN_CLASS     = 4;
  433.   INTEGER XIP_TEAL_CLASS      = 5;
  434.   INTEGER XIP_CYAN_CLASS      = 6;
  435.   INTEGER XIP_AZURE_CLASS     = 7;
  436.   INTEGER XIP_BLUE_CLASS      = 8;
  437.   INTEGER XIP_VIOLET_CLASS    = 9;
  438.   INTEGER XIP_MAGENTA_CLASS   =10;
  439.   INTEGER XIP_PINK_CLASS      =11;
  440.   INTEGER XIP_BLACK_CLASS     =12;
  441.   INTEGER XIP_GRAY_CLASS      =13;
  442.   INTEGER XIP_WHITE_CLASS     =14;
  443.   INTEGER XIP_UNKNOWN_CLASS   =15;
  444.  
  445.   colorname = XIPColorName (color: color);
  446.  
  447.   if (colorname.strcasecmp (str: "black")) {
  448.     classid = XIP_BLACK_CLASS;
  449.   } else if (colorname.strcasecmp (str: "white")) {
  450.     classid = XIP_WHITE_CLASS;
  451.   } else if (colorname.strcasecmp (str: "dark gray") ||
  452.              colorname.strcasecmp (str: "gray") ||
  453.              colorname.strcasecmp (str: "light gray")) {
  454.     classid = XIP_GRAY_CLASS;
  455.   } else if (colorname.strcasecmp (str: "red")) {
  456.     classid = XIP_RED_CLASS;
  457.   } else if (colorname.strcasecmp (str: "orange")) {
  458.     classid = XIP_ORANGE_CLASS;
  459.   } else if (colorname.strcasecmp (str: "yellow")) {
  460.     classid = XIP_YELLOW_CLASS;
  461.   } else if (colorname.strcasecmp (str: "spring")) {
  462.     classid = XIP_SPRING_CLASS;
  463.   } else if (colorname.strcasecmp (str: "green")) {
  464.     classid = XIP_GREEN_CLASS;
  465.   } else if (colorname.strcasecmp (str: "teal")) {
  466.     classid = XIP_TEAL_CLASS;
  467.   } else if (colorname.strcasecmp (str: "cyan")) {
  468.     classid = XIP_CYAN_CLASS;
  469.   } else if (colorname.strcasecmp (str: "azure")) {
  470.     classid = XIP_AZURE_CLASS;
  471.   } else if (colorname.strcasecmp (str: "blue")) {
  472.     classid = XIP_BLUE_CLASS;
  473.   } else if (colorname.strcasecmp (str: "violet") ||
  474.              colorname.strcasecmp (str: "purple")) {
  475.     classid = XIP_VIOLET_CLASS;
  476.   } else if (colorname.strcasecmp (str: "magenta")) {
  477.     classid  = XIP_MAGENTA_CLASS;
  478.   } else if (colorname.strcasecmp (str: "pink")) {
  479.     classid = XIP_PINK_CLASS;
  480.   } else {
  481.     classid = XIP_UNKNOWN_CLASS;
  482.   }
  483. }
  484.